package org.common.utils.fasttest;

import groovy.lang.GroovyShell;


/**
 * @author zhouzhibing
 * @date 2024/6/14
 */
public class  TestGroovy{
    private static  final GroovyShell GROOVY_SHELL = new GroovyShell();

    private static  final String message = "TestGroovy";
    public static void test() {
        GROOVY_SHELL.setProperty("message" , message);

        GROOVY_SHELL.evaluate(getTest1());
    }


    private static String getTest0() {
        return """
                 import org.example.entity.RoleResourceModel
                            import org.example.entity.TestService
                           \s
                            mode = new RoleResourceModel()
                            mode.diamond = "sssss"
                           \s
                            def test() {
                                println( "test : hello groovy $mode")
                                println( "mode " + this)
                            }
                           \s
                            test()
                """;
    }

    private static String getTest1() {
        return """
                void testVarScope(){
                    a = 111
                    def b = 222
                }
                //println a
                //println b
                                
                //块内定义，不使用def,全局可见
                if(true){
                    def email = "sky@gmail.com"
                    //email = "sky@gmail.com"
                    println "in code block email=$email"
                }
                println "out of block email=$email"
                                
                //没有用def定义
                num = 5
                println binding.variables.num == 5
                //用def定义
                def name = "sky"
                println binding.variables.name
                println "ok"
                """;
    }
}



